package com.example.g5project.chat.util;

import com.example.g5project.chat.model.common.AccountParam;
import com.example.g5project.chat.model.enumeration.IdentityEnum;
import javax.annotation.Resource;
import org.springframework.stereotype.Component;

@Component
public class IMUserIdUtils {

    @Resource
    private TencentImUtils tencentImUtils;

    /**
     * 腾讯IM账号导入
     *
     * @param id
     * @param identityEnum
     */
    public String importUserId(Integer id, IdentityEnum identityEnum) {
        if (id == null || id <= 0) {
            throw new IllegalArgumentException("id不合法");
        }
        String imUserId = this.getIMUserId(id, identityEnum);
        tencentImUtils.accountImport(imUserId);
        return imUserId;
    }

    /**
     * 获取对应身份下的IM账号
     *
     * @param id
     * @param identityEnum
     * @return
     */
    public String getIMUserId(Integer id, IdentityEnum identityEnum) {
        if (id == null || id <= 0) {
            throw new IllegalArgumentException("id不合法");
        }
        return identityEnum.getPrefix() + id;
    }

    /**
     * 获取对应身份下的IM账号
     *
     * @param accountParam
     * @return
     */
    public String getIMUserId(AccountParam accountParam) {
        Integer accountId = accountParam.getAccountId();
        IdentityEnum identityEnum = IdentityEnum.parseById(accountParam.getAccountIdentity());
        return this.getIMUserId(accountId, identityEnum);
    }

}
